#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int g_val = 100;

int main()
{
  printf("father is runing, pid: %d, ppid: %d\n", getpid(), getppid());
  sleep(2);

  pid_t id = fork();
  int cnt = 3;
  while(1)
  {
    if(id == 0)
    {
      printf("I am child process, pid: %d, ppid: %d, g_val: %d, &g_val: %p\n", getpid(), getppid(), g_val, &g_val);
      sleep(1);
      cnt--;
      if(cnt == 0)
      {
        g_val = 300;
        printf("I am child, g_val is changed, 100 -> 300\n");
      }
    }
    else
    {
      printf("I am father process, pid: %d, ppid: %d, g_val: %d, &g_val: %p\n", getpid(), getppid(), g_val, &g_val);
      sleep(1);
    }
  }

  return 0;
}
